#! /usr/bin/env Rscript
# Este script grafica (en archivos png) la evolucion del Gold Standard a medida que se consideran
# mayor cantidad de palabras en la base de conocimiento.
setwd("/Users/matias/Documents/facultad/tesis/goldStandard/estadisticas/")
# Estos valores se calculan con GSvsCantPalabrasCorrelacion del proyecto ocovinu en java.
cantPalabras = c(250,350,450,550,650,750,850,950,1050,1150,1250,1350,1450,1550,1650,1750,1850,1950,2050,2150,2250,2350,2450,2550)
agrado = c(-0.023133301389593092,-0.004994767976313704,0.2747921472236831,0.30731613541692165,0.35154802707989946,0.4242256808588278,0.4442226123324769,0.4514510355501146,0.4589741813906045,0.45883964732179155,0.44688129497533624,0.4821996157552154,0.46356988893770085,0.4840349715730998,0.4889375913796493,0.48573067470877784,0.46539265662240237,0.47752452160349196,0.5524737677385665,0.5656790240493931,0.5786287462879444,0.5751758743264015,0.5959775330702435,0.5897896277753086)
act = c(-0.06834044354984035,-0.06128220394797716,0.22773452620220458,0.3388738604185446,0.3407493851218932,0.3136239921440497,0.35280565009038817,0.3718934019846103,0.4301687622219564,0.4481764961838448,0.42553433103241906,0.42577779685520417,0.418584816720864,0.33047270658313566,0.34911702823870716,0.3375763152544795,0.3542202620181936,0.4416208167058188,0.48541530786097153,0.47871620013085936,0.4417471664813519,0.4289114962310518,0.4086741467381816,0.409543081560062)
img = c(-0.1300763170253585,-0.10530091609563125,0.019945253481824,0.02708153281081321,0.048612570423245634,0.0834453073959667,0.09127660933104155,0.10854250883516778,0.09965042166276425,0.09839952567738022,0.10207197991811902,0.11640128646555395,0.1311687686658813,0.1089278327306858,0.12465104403184357,0.1272475484263727,0.12428333030395362,0.10726720721619845,0.11377072983552702,0.10822593616993237,0.08704104463869207,0.07379051933225297,0.07337218001778029,0.06920001662551145)
coverage = c(18.444302178239354,21.285922668969715,24.60223252970129,26.740032371745365,28.37576031285482,30.222104225829533,30.921646845829812,31.799679054652074,32.9134745644238,33.88369931401282,34.96204753335335,36.126589535169444,37.69398322022127,38.87706631389473,39.25956199777163,39.64786731990048,40.39598108936638,41.06768694121317,41.65612064135226,42.51768109537329,43.00402059731579,43.17988639818159,43.923276259305624,44.399255397342294)

png(file="correlacionesCubrimientoGS.png", width=450, height=400)
par(mar=c(5,4,4,5)+.1)
plot(cantPalabras,agrado,type="o", pch=21, col="blue", ylim=c(-0.2,1), xlab="Cant. Palabras", ylab="Correlación")
lines(cantPalabras, act, type="o", pch=22, col="red")
lines(cantPalabras, img, type="o", pch=23, col="violet")

fitAgrado = nls(agrado~((c*log(cantPalabras)+b)), start=list(c=0.1828,b=0.0159), control=list(maxiter=200))
lines(cantPalabras, predict(fitAgrado), col="black")
points(cantPalabras, predict(fitAgrado), col="black", pch="*")
#R^2=0.89991

fitAct = nls(act~((c*log(cantPalabras)+b)), start=list(c=0.144,b=0.0226), control=list(maxiter=200))
lines(cantPalabras, predict(fitAct), col="black")
points(cantPalabras, predict(fitAct), col="black", pch="*")
#R^2=0.71655

fitImg = nls(img~((c*log(cantPalabras)+b)), start=list(c=0.066,b=-0.0752), control=list(maxiter=200))
lines(cantPalabras, predict(fitImg), col="black")
points(cantPalabras, predict(fitImg), col="black", pch="*")
#R^2=0.68067

par(new=TRUE)
plot(cantPalabras,coverage,,type="o",pch=24, ylim=c(15,45),col="green",xaxt="n",yaxt="n",xlab="",ylab="")
axis(4)
mtext("% Cubrimiento",side=4,line=3)
title(main="Evolución de la correlación", col.main="black", font.main=4)
legend("topleft", c("Agrado","Activación","Imaginabilidad", "Cubrimiento"), cex=0.8, col=c("blue","red","violet","green"), pch=21:24, lty=1)
dev.off()

# y=(c*LN(x))+b
# c = index(linest(y,LN(x)),1)
# b = index(linest(y,LN(x)),1,2)
# RSQ = RSQ(y,LN(X))
